<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Auth extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->library('form_validation');
		$this->load->model('user_model');
	}
	public function login()
	{
		$data['error']= '';
		$this->form_validation->set_rules('form_username', 'username', 'trim|xss_clean|required');
		$this->form_validation->set_rules('form_password', 'password', 'trim|xss_clean|required');
		if($this->form_validation->run()){
			if($this->user_model->login(
				$this->form_validation->set_value('form_username'),
				$this->form_validation->set_value('form_password')
			)){
				redirect('/admin');
			}else{
				$data['error'] = '登录失败';
			}
		}
		$this->load->view('login.tpl',$data);
	}

	public function logout(){
		$this->session->unset_userdata('uid');
		$this->session->unset_userdata('uname');
		redirect('/');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */